export default {
	namespaced:true,
	state:()=>{
		return {
			address:JSON.parse(uni.getStorageSync('address')  || '{}'),
			token:uni.getStorageSync('token') || '',
			userInfo :JSON.parse(uni.getStorageSync('userInfo') || '{}'),
			//跳转的路径及方式
			navigateInfo:null,
		}
	},
	mutations:{
		//更新跳转的路径及方式
		updateNavigateInfo(state,navigateInfo){
			state.navigateInfo = navigateInfo;
		},
		//更新token
		updateToken(state,token){
			state.token = token;
			this.commit('user_m/saveTokenToStorage');
		},
		saveTokenToStorage(state){
			//token 本身就是加密过的字符串，所有不需要转
			uni.setStorageSync('token',state.token);
		},
		
		//更新用户基本信息
		updateUserInfo(state,userInfo){
			state.userInfo = userInfo;
			//持续化存储
			this.commit('user_m/saveUserInfoToStorage');
		},
		saveUserInfoToStorage(state){
			uni.setStorageSync('userInfo',JSON.stringify(state.userInfo));
		},
		
		// 更新收货地址
		updateAddress(state,address){
			state.address = address;
			this.commit('user_m/saveAddressToStorage')
		},
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address));
		}
	},
	actions:{},
	getters:{
		addressStr(state){
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}